//
//  SDDetectionReportData.m
//
//  Created by   on 2018/11/22
//  Copyright (c) 2018 __MyCompanyName__. All rights reserved.
//

#import "SDDetectionReportData.h"


NSString *const kSDDetectionReportDataResImg4List = @"resImg4List";
NSString *const kSDDetectionReportDataResImg3List = @"resImg3List";
NSString *const kSDDetectionReportDataSkinType = @"skinType";
NSString *const kSDDetectionReportDataResImg2Desc = @"resImg2Desc";
NSString *const kSDDetectionReportDataNickName = @"nickName";
NSString *const kSDDetectionReportDataResImg2List = @"resImg2List";
NSString *const kSDDetectionReportDataResImg1Desc = @"resImg1Desc";
NSString *const kSDDetectionReportDataResImg2 = @"resImg2";
NSString *const kSDDetectionReportDataResImg1List = @"resImg1List";
NSString *const kSDDetectionReportDataResImg1SubId = @"resImg1SubId";
NSString *const kSDDetectionReportDataSex = @"sex";
NSString *const kSDDetectionReportDataResImg3 = @"resImg3";
NSString *const kSDDetectionReportDataScore = @"score";
NSString *const kSDDetectionReportDataResImg3SubId = @"resImg3SubId";
NSString *const kSDDetectionReportDataResImg4 = @"resImg4";
NSString *const kSDDetectionReportDataResImg5SubId = @"resImg5SubId";
NSString *const kSDDetectionReportDataResImg5 = @"resImg5";
NSString *const kSDDetectionReportDataId = @"id";
NSString *const kSDDetectionReportDataResImg5Desc = @"resImg5Desc";
NSString *const kSDDetectionReportDataResImg2SubId = @"resImg2SubId";
NSString *const kSDDetectionReportDataResImg5List = @"resImg5List";
NSString *const kSDDetectionReportDataCreateTime = @"createTime";
NSString *const kSDDetectionReportDataResImg4Desc = @"resImg4Desc";
NSString *const kSDDetectionReportDataResImg4SubId = @"resImg4SubId";
NSString *const kSDDetectionReportDataResImg1 = @"resImg1";
NSString *const kSDDetectionReportDataResImg3Desc = @"resImg3Desc";


@interface SDDetectionReportData ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation SDDetectionReportData

@synthesize resImg4List = _resImg4List;
@synthesize resImg3List = _resImg3List;
@synthesize skinType = _skinType;
@synthesize resImg2Desc = _resImg2Desc;
@synthesize nickName = _nickName;
@synthesize resImg2List = _resImg2List;
@synthesize resImg1Desc = _resImg1Desc;
@synthesize resImg2 = _resImg2;
@synthesize resImg1List = _resImg1List;
@synthesize resImg1SubId = _resImg1SubId;
@synthesize sex = _sex;
@synthesize resImg3 = _resImg3;
@synthesize score = _score;
@synthesize resImg3SubId = _resImg3SubId;
@synthesize resImg4 = _resImg4;
@synthesize resImg5SubId = _resImg5SubId;
@synthesize resImg5 = _resImg5;
@synthesize id = _id;
@synthesize resImg5Desc = _resImg5Desc;
@synthesize resImg2SubId = _resImg2SubId;
@synthesize resImg5List = _resImg5List;
@synthesize createTime = _createTime;
@synthesize resImg4Desc = _resImg4Desc;
@synthesize resImg4SubId = _resImg4SubId;
@synthesize resImg1 = _resImg1;
@synthesize resImg3Desc = _resImg3Desc;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict {
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict {
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if (self && [dict isKindOfClass:[NSDictionary class]]) {
            self.resImg4List = [self objectOrNilForKey:kSDDetectionReportDataResImg4List fromDictionary:dict];
            self.resImg3List = [self objectOrNilForKey:kSDDetectionReportDataResImg3List fromDictionary:dict];
            self.skinType = [self objectOrNilForKey:kSDDetectionReportDataSkinType fromDictionary:dict];
            self.resImg2Desc = [self objectOrNilForKey:kSDDetectionReportDataResImg2Desc fromDictionary:dict];
            self.nickName = [self objectOrNilForKey:kSDDetectionReportDataNickName fromDictionary:dict];
            self.resImg2List = [self objectOrNilForKey:kSDDetectionReportDataResImg2List fromDictionary:dict];
            self.resImg1Desc = [self objectOrNilForKey:kSDDetectionReportDataResImg1Desc fromDictionary:dict];
            self.resImg2 = [self objectOrNilForKey:kSDDetectionReportDataResImg2 fromDictionary:dict];
            self.resImg1List = [self objectOrNilForKey:kSDDetectionReportDataResImg1List fromDictionary:dict];
            self.resImg1SubId = [[self objectOrNilForKey:kSDDetectionReportDataResImg1SubId fromDictionary:dict] doubleValue];
            self.sex = [self objectOrNilForKey:kSDDetectionReportDataSex fromDictionary:dict];
            self.resImg3 = [self objectOrNilForKey:kSDDetectionReportDataResImg3 fromDictionary:dict];
            self.score = [[self objectOrNilForKey:kSDDetectionReportDataScore fromDictionary:dict] doubleValue];
            self.resImg3SubId = [[self objectOrNilForKey:kSDDetectionReportDataResImg3SubId fromDictionary:dict] doubleValue];
            self.resImg4 = [self objectOrNilForKey:kSDDetectionReportDataResImg4 fromDictionary:dict];
            self.resImg5SubId = [[self objectOrNilForKey:kSDDetectionReportDataResImg5SubId fromDictionary:dict] doubleValue];
            self.resImg5 = [self objectOrNilForKey:kSDDetectionReportDataResImg5 fromDictionary:dict];
            self.id = [[self objectOrNilForKey:kSDDetectionReportDataId fromDictionary:dict] doubleValue];
            self.resImg5Desc = [self objectOrNilForKey:kSDDetectionReportDataResImg5Desc fromDictionary:dict];
            self.resImg2SubId = [[self objectOrNilForKey:kSDDetectionReportDataResImg2SubId fromDictionary:dict] doubleValue];
            self.resImg5List = [self objectOrNilForKey:kSDDetectionReportDataResImg5List fromDictionary:dict];
            self.createTime = [[self objectOrNilForKey:kSDDetectionReportDataCreateTime fromDictionary:dict] doubleValue];
            self.resImg4Desc = [self objectOrNilForKey:kSDDetectionReportDataResImg4Desc fromDictionary:dict];
            self.resImg4SubId = [[self objectOrNilForKey:kSDDetectionReportDataResImg4SubId fromDictionary:dict] doubleValue];
            self.resImg1 = [self objectOrNilForKey:kSDDetectionReportDataResImg1 fromDictionary:dict];
            self.resImg3Desc = [self objectOrNilForKey:kSDDetectionReportDataResImg3Desc fromDictionary:dict];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation {
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    NSMutableArray *tempArrayForResImg4List = [NSMutableArray array];
    
    for (NSObject *subArrayObject in self.resImg4List) {
        if ([subArrayObject respondsToSelector:@selector(dictionaryRepresentation)]) {
            // This class is a model object
            [tempArrayForResImg4List addObject:[subArrayObject performSelector:@selector(dictionaryRepresentation)]];
        } else {
            // Generic object
            [tempArrayForResImg4List addObject:subArrayObject];
        }
    }
    [mutableDict setValue:[NSArray arrayWithArray:tempArrayForResImg4List] forKey:kSDDetectionReportDataResImg4List];
    NSMutableArray *tempArrayForResImg3List = [NSMutableArray array];
    
    for (NSObject *subArrayObject in self.resImg3List) {
        if ([subArrayObject respondsToSelector:@selector(dictionaryRepresentation)]) {
            // This class is a model object
            [tempArrayForResImg3List addObject:[subArrayObject performSelector:@selector(dictionaryRepresentation)]];
        } else {
            // Generic object
            [tempArrayForResImg3List addObject:subArrayObject];
        }
    }
    [mutableDict setValue:[NSArray arrayWithArray:tempArrayForResImg3List] forKey:kSDDetectionReportDataResImg3List];
    [mutableDict setValue:self.skinType forKey:kSDDetectionReportDataSkinType];
    [mutableDict setValue:self.resImg2Desc forKey:kSDDetectionReportDataResImg2Desc];
    [mutableDict setValue:self.nickName forKey:kSDDetectionReportDataNickName];
    NSMutableArray *tempArrayForResImg2List = [NSMutableArray array];
    
    for (NSObject *subArrayObject in self.resImg2List) {
        if ([subArrayObject respondsToSelector:@selector(dictionaryRepresentation)]) {
            // This class is a model object
            [tempArrayForResImg2List addObject:[subArrayObject performSelector:@selector(dictionaryRepresentation)]];
        } else {
            // Generic object
            [tempArrayForResImg2List addObject:subArrayObject];
        }
    }
    [mutableDict setValue:[NSArray arrayWithArray:tempArrayForResImg2List] forKey:kSDDetectionReportDataResImg2List];
    [mutableDict setValue:self.resImg1Desc forKey:kSDDetectionReportDataResImg1Desc];
    [mutableDict setValue:self.resImg2 forKey:kSDDetectionReportDataResImg2];
    NSMutableArray *tempArrayForResImg1List = [NSMutableArray array];
    
    for (NSObject *subArrayObject in self.resImg1List) {
        if ([subArrayObject respondsToSelector:@selector(dictionaryRepresentation)]) {
            // This class is a model object
            [tempArrayForResImg1List addObject:[subArrayObject performSelector:@selector(dictionaryRepresentation)]];
        } else {
            // Generic object
            [tempArrayForResImg1List addObject:subArrayObject];
        }
    }
    [mutableDict setValue:[NSArray arrayWithArray:tempArrayForResImg1List] forKey:kSDDetectionReportDataResImg1List];
    [mutableDict setValue:[NSNumber numberWithDouble:self.resImg1SubId] forKey:kSDDetectionReportDataResImg1SubId];
    [mutableDict setValue:self.sex forKey:kSDDetectionReportDataSex];
    [mutableDict setValue:self.resImg3 forKey:kSDDetectionReportDataResImg3];
    [mutableDict setValue:[NSNumber numberWithDouble:self.score] forKey:kSDDetectionReportDataScore];
    [mutableDict setValue:[NSNumber numberWithDouble:self.resImg3SubId] forKey:kSDDetectionReportDataResImg3SubId];
    [mutableDict setValue:self.resImg4 forKey:kSDDetectionReportDataResImg4];
    [mutableDict setValue:[NSNumber numberWithDouble:self.resImg5SubId] forKey:kSDDetectionReportDataResImg5SubId];
    [mutableDict setValue:self.resImg5 forKey:kSDDetectionReportDataResImg5];
    [mutableDict setValue:[NSNumber numberWithDouble:self.id] forKey:kSDDetectionReportDataId];
    [mutableDict setValue:self.resImg5Desc forKey:kSDDetectionReportDataResImg5Desc];
    [mutableDict setValue:[NSNumber numberWithDouble:self.resImg2SubId] forKey:kSDDetectionReportDataResImg2SubId];
    NSMutableArray *tempArrayForResImg5List = [NSMutableArray array];
    
    for (NSObject *subArrayObject in self.resImg5List) {
        if ([subArrayObject respondsToSelector:@selector(dictionaryRepresentation)]) {
            // This class is a model object
            [tempArrayForResImg5List addObject:[subArrayObject performSelector:@selector(dictionaryRepresentation)]];
        } else {
            // Generic object
            [tempArrayForResImg5List addObject:subArrayObject];
        }
    }
    [mutableDict setValue:[NSArray arrayWithArray:tempArrayForResImg5List] forKey:kSDDetectionReportDataResImg5List];
    [mutableDict setValue:[NSNumber numberWithDouble:self.createTime] forKey:kSDDetectionReportDataCreateTime];
    [mutableDict setValue:self.resImg4Desc forKey:kSDDetectionReportDataResImg4Desc];
    [mutableDict setValue:[NSNumber numberWithDouble:self.resImg4SubId] forKey:kSDDetectionReportDataResImg4SubId];
    [mutableDict setValue:self.resImg1 forKey:kSDDetectionReportDataResImg1];
    [mutableDict setValue:self.resImg3Desc forKey:kSDDetectionReportDataResImg3Desc];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description  {
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict {
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder {
    self = [super init];

    self.resImg4List = [aDecoder decodeObjectForKey:kSDDetectionReportDataResImg4List];
    self.resImg3List = [aDecoder decodeObjectForKey:kSDDetectionReportDataResImg3List];
    self.skinType = [aDecoder decodeObjectForKey:kSDDetectionReportDataSkinType];
    self.resImg2Desc = [aDecoder decodeObjectForKey:kSDDetectionReportDataResImg2Desc];
    self.nickName = [aDecoder decodeObjectForKey:kSDDetectionReportDataNickName];
    self.resImg2List = [aDecoder decodeObjectForKey:kSDDetectionReportDataResImg2List];
    self.resImg1Desc = [aDecoder decodeObjectForKey:kSDDetectionReportDataResImg1Desc];
    self.resImg2 = [aDecoder decodeObjectForKey:kSDDetectionReportDataResImg2];
    self.resImg1List = [aDecoder decodeObjectForKey:kSDDetectionReportDataResImg1List];
    self.resImg1SubId = [aDecoder decodeDoubleForKey:kSDDetectionReportDataResImg1SubId];
    self.sex = [aDecoder decodeObjectForKey:kSDDetectionReportDataSex];
    self.resImg3 = [aDecoder decodeObjectForKey:kSDDetectionReportDataResImg3];
    self.score = [aDecoder decodeDoubleForKey:kSDDetectionReportDataScore];
    self.resImg3SubId = [aDecoder decodeDoubleForKey:kSDDetectionReportDataResImg3SubId];
    self.resImg4 = [aDecoder decodeObjectForKey:kSDDetectionReportDataResImg4];
    self.resImg5SubId = [aDecoder decodeDoubleForKey:kSDDetectionReportDataResImg5SubId];
    self.resImg5 = [aDecoder decodeObjectForKey:kSDDetectionReportDataResImg5];
    self.id = [aDecoder decodeDoubleForKey:kSDDetectionReportDataId];
    self.resImg5Desc = [aDecoder decodeObjectForKey:kSDDetectionReportDataResImg5Desc];
    self.resImg2SubId = [aDecoder decodeDoubleForKey:kSDDetectionReportDataResImg2SubId];
    self.resImg5List = [aDecoder decodeObjectForKey:kSDDetectionReportDataResImg5List];
    self.createTime = [aDecoder decodeDoubleForKey:kSDDetectionReportDataCreateTime];
    self.resImg4Desc = [aDecoder decodeObjectForKey:kSDDetectionReportDataResImg4Desc];
    self.resImg4SubId = [aDecoder decodeDoubleForKey:kSDDetectionReportDataResImg4SubId];
    self.resImg1 = [aDecoder decodeObjectForKey:kSDDetectionReportDataResImg1];
    self.resImg3Desc = [aDecoder decodeObjectForKey:kSDDetectionReportDataResImg3Desc];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeObject:_resImg4List forKey:kSDDetectionReportDataResImg4List];
    [aCoder encodeObject:_resImg3List forKey:kSDDetectionReportDataResImg3List];
    [aCoder encodeObject:_skinType forKey:kSDDetectionReportDataSkinType];
    [aCoder encodeObject:_resImg2Desc forKey:kSDDetectionReportDataResImg2Desc];
    [aCoder encodeObject:_nickName forKey:kSDDetectionReportDataNickName];
    [aCoder encodeObject:_resImg2List forKey:kSDDetectionReportDataResImg2List];
    [aCoder encodeObject:_resImg1Desc forKey:kSDDetectionReportDataResImg1Desc];
    [aCoder encodeObject:_resImg2 forKey:kSDDetectionReportDataResImg2];
    [aCoder encodeObject:_resImg1List forKey:kSDDetectionReportDataResImg1List];
    [aCoder encodeDouble:_resImg1SubId forKey:kSDDetectionReportDataResImg1SubId];
    [aCoder encodeObject:_sex forKey:kSDDetectionReportDataSex];
    [aCoder encodeObject:_resImg3 forKey:kSDDetectionReportDataResImg3];
    [aCoder encodeDouble:_score forKey:kSDDetectionReportDataScore];
    [aCoder encodeDouble:_resImg3SubId forKey:kSDDetectionReportDataResImg3SubId];
    [aCoder encodeObject:_resImg4 forKey:kSDDetectionReportDataResImg4];
    [aCoder encodeDouble:_resImg5SubId forKey:kSDDetectionReportDataResImg5SubId];
    [aCoder encodeObject:_resImg5 forKey:kSDDetectionReportDataResImg5];
    [aCoder encodeDouble:_id forKey:kSDDetectionReportDataId];
    [aCoder encodeObject:_resImg5Desc forKey:kSDDetectionReportDataResImg5Desc];
    [aCoder encodeDouble:_resImg2SubId forKey:kSDDetectionReportDataResImg2SubId];
    [aCoder encodeObject:_resImg5List forKey:kSDDetectionReportDataResImg5List];
    [aCoder encodeDouble:_createTime forKey:kSDDetectionReportDataCreateTime];
    [aCoder encodeObject:_resImg4Desc forKey:kSDDetectionReportDataResImg4Desc];
    [aCoder encodeDouble:_resImg4SubId forKey:kSDDetectionReportDataResImg4SubId];
    [aCoder encodeObject:_resImg1 forKey:kSDDetectionReportDataResImg1];
    [aCoder encodeObject:_resImg3Desc forKey:kSDDetectionReportDataResImg3Desc];
}

- (id)copyWithZone:(NSZone *)zone {
    SDDetectionReportData *copy = [[SDDetectionReportData alloc] init];
    
    
    
    if (copy) {

        copy.resImg4List = [self.resImg4List copyWithZone:zone];
        copy.resImg3List = [self.resImg3List copyWithZone:zone];
        copy.skinType = [self.skinType copyWithZone:zone];
        copy.resImg2Desc = [self.resImg2Desc copyWithZone:zone];
        copy.nickName = [self.nickName copyWithZone:zone];
        copy.resImg2List = [self.resImg2List copyWithZone:zone];
        copy.resImg1Desc = [self.resImg1Desc copyWithZone:zone];
        copy.resImg2 = [self.resImg2 copyWithZone:zone];
        copy.resImg1List = [self.resImg1List copyWithZone:zone];
        copy.resImg1SubId = self.resImg1SubId;
        copy.sex = [self.sex copyWithZone:zone];
        copy.resImg3 = [self.resImg3 copyWithZone:zone];
        copy.score = self.score;
        copy.resImg3SubId = self.resImg3SubId;
        copy.resImg4 = [self.resImg4 copyWithZone:zone];
        copy.resImg5SubId = self.resImg5SubId;
        copy.resImg5 = [self.resImg5 copyWithZone:zone];
        copy.id = self.id;
        copy.resImg5Desc = [self.resImg5Desc copyWithZone:zone];
        copy.resImg2SubId = self.resImg2SubId;
        copy.resImg5List = [self.resImg5List copyWithZone:zone];
        copy.createTime = self.createTime;
        copy.resImg4Desc = [self.resImg4Desc copyWithZone:zone];
        copy.resImg4SubId = self.resImg4SubId;
        copy.resImg1 = [self.resImg1 copyWithZone:zone];
        copy.resImg3Desc = [self.resImg3Desc copyWithZone:zone];
    }
    
    return copy;
}


@end
